<template>
    <div class="container">
        <div class="row pt-5">
            <div class="col-md-12">
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title">疫苗制造方制造疫苗</h5>
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗名称</span>
                    <input id="name" type="text" class="form-control" placeholder="输入疫苗名称">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗状态(0表示固态,1表示液态,2表示气态)</span>
                    <input id="state" type="number" max="2" min="0" oninput="if(value>2)value=2;if(value.length>4)value=value.slice(0,4);if(value<0)value=0" class="form-control" placeholder="输入该批疫苗状态">
                  </div>  
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗批号</span>
                    <input id="batchId" type="number" class="form-control" placeholder="输入该批疫苗的批号">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">该批疫苗的保质期(单位月)</span>
                    <input id="periodOfValidity" type="number" max="12" min="1" oninput="if(value>12)value=12;if(value.length>4)value=value.slice(0,4);if(value<1)value=1" class="form-control" placeholder="输入该批疫苗的保质期(单位月)">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗简介</span>
                    <input id="intro" type="text" class="form-control" placeholder="输入此批疫苗简介">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗数量</span>
                    <input id="num" type="number" max="100" min="1" oninput="if(value>100)value=100;if(value.length>4)value=value.slice(0,4);if(value<1)value=1" class="form-control" placeholder="输入该批疫苗数量">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">疫苗生产时间</span>
                    <input id="time" type="datetime-local" class="form-control" placeholder="输入生产日期">
                  </div>
                  <button class="btn btn-primary" id="produce" @click='produce' type="button">确认制造</button>
                </div>
              </div>
            </div>
            <div class="col-md-12 pt-5">
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title">疫苗制造方认证系统</h5>
                  <div class="input-group mb-3">
                    <span class="input-group-text">企业地址</span>
                    <input id="addr" type="text" class="form-control" placeholder="输入企业地址">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">认证方(0为仓储,1为运输,2为医院)</span>
                    <input id="temp" type="number" class="form-control" placeholder="输入需要验证方">
                  </div>
                  <div class="input-group mb-3">
                    <span class="input-group-text">企业名称</span>
                    <input id="name1" type="text" class="form-control" placeholder="输入企业名称">
                  </div>
                  <button class="btn btn-primary" id="choiceEnterprise" @click='choiceEnterprise' type="button">认证完成</button>
                </div>
              </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:'MyFactor',
    methods:{
      async produce(){
        var name = $('#name').val();
        var state = $('#state').val();
        var batchId = $('#batchId').val();
        var periodOfValidity = $('#periodOfValidity').val();
        var intro = $('#intro').val();
        var num = $('#num').val();
        var time = $('#time').val();
        await this.$Appjs.methods
      .produce(name,parseInt(state),parseInt(batchId),parseInt(periodOfValidity),intro,parseInt(num),time.toString())
        .send({
        from:"0xbD7eFb6A883186bf6Bd53Ad1DcA58465276cfCac"
        })
        alert('制造成功!')
      },
      async choiceEnterprise(){
        var addr = $('#addr').val();
        var temp = $('#temp').val();
        var name1 = $('#name1').val()+"->";
        await this.$Appjs.methods
      .choiceEnterprise(addr,parseInt(temp),name1).send({
        from:"0xbD7eFb6A883186bf6Bd53Ad1DcA58465276cfCac",
        gas: 150000,
        gasPrice: 3000000000,
        //value: 3000000
      })
      alert('认证完成!')
    },
  }
}
</script>

<style>

</style>